<template>
    <div class="app-container">
        <el-table v-loading="listLoading" element-loading-text="正在载入数据..." :data="dataList" style="width: 100%;" border class="data-list">
            <el-table-column label="序号" align="center" type="index" :index="indexMethod" width="50">

            </el-table-column>
            <el-table-column label="发送时间" align="center" width="180">
                <template slot-scope="scope">
                   {{scope.row.createTime | formatDate}}
                </template>
            </el-table-column>
            <el-table-column label="发送电话号码" align="center" width="180">
                <template slot-scope="scope">
                   {{scope.row.smsPhone | formatString}}
                </template>
            </el-table-column>
            <el-table-column label="短信内容" align="left" prop="content">
            </el-table-column>
        </el-table>
        <pagination v-show="total>0" :total="total" :page.sync="pageData.currPage" :limit.sync="pageData.pageSize" @pagination="getPaginationData" />
    </div>
   
</template>
<script>
import Pagination from '@/components/Pagination'
export default {
    components: {Pagination},
    props: ['shopId'],
    data () {
        return {
            phone: '',
            selectedSend: '',
            listLoading: false,
            dataList: [],
            pageData:{
                currPage: 1,
                pageSize: 20
            },
            total: 0
        }
    },
    created() {
        var self = this;
    },
    methods: {
        fetchData() {
            var self = this;
            let data = {
                shopId: self.shopId
            }
            self.listLoading = true;
            self.$axios.post(API_ROOT.url + '/openSmsMessage/querySmsIndex?shopId=' + self.shopId).then(result => {
                if(result.status){
                    let data = result.data.data;
                    self.dataList = data.list;
                    self.total = data.total;
                    self.pageData.pageSize = data.pageSize;
                    self.pageData.currPage = data.pageNum;
                }else{
                    self.$alert(result.message)
                }
                self.listLoading = false;
            }).catch(err => {
                self.listLoading = false;
            });
        },

         getPaginationData(){
            let self = this;
            let data = {
                shopId: self.shopId,
                pageNo: self.pageData.currPage
            };
            self.$axios.post(API_ROOT.url + '/openSmsMessage/querySms', data).then(res => {
                if(res.status){
                    let data = res.data.data;
                    self.dataList = data.list;
                }
            }).catch(err => {
                self.$message.error('请求失败，请稍后再试！');
            });
        },
        
        indexMethod(idx) {
            return idx + 1;
        },

        sendMsgHandle() {
            var self = this,
                data = {
                    phone: self.phone,
                    content: self.selectedSend
                };
            self.$axios.post(API_ROOT.url, data).then(res => {
                if(res.status){
                    self.$alert(res.message);
                }else{
                    self.$alert('发送短信出错：' + res.message);
                }
            }).catch(err => {
                self.$message.error('请求失败，请稍后再试！');
            })
        }
    }
}
</script>

